import React, { Component } from "react";
//对类型进行限制
import PropTypes from "prop-types";
import Item from "../Item";
import "./index.css";
export default class List extends Component {
  //对传过来的props进行类型和必要性的限制
  //todos:类型为数组array
  //updateTodo：类型为fun
  static propTypes = {
    todos: PropTypes.array.isRequired,
    updateTodo: PropTypes.func.isRequired,
    deleteTodo: PropTypes.func.isRequired,
  };

  render() {
    const { todos, updateTodo, deleteTodo } = this.props;
    return (
      <div>
        <ul className="todo-main">
          {todos.map((item, index) => {
            return (
              <Item
                key={item.id}
                {...item}
                updateTodo={updateTodo}
                deleteTodo={deleteTodo}
              />
            );
          })}
        </ul>
      </div>
    );
  }
}
